package bit_operation;

/**
 * @Description ipv4 -> int32
 * @Author Firenut
 * @Date 2023-08-24 19:45
 */
public class IPV4ToInt {
    public static void main(String[] args) {
        System.out.println(ipToInt("10.0.3.193"));
    }
    static int ipToInt(String ip) {
        int[] segment = new int[4];
        String[] split = ip.split("\\.");
        for (int i = 0; i < split.length; i++) {
            segment[i] = Integer.parseInt(split[i]);
            segment[i] <<= (8 * (3 - i));
        }
        return segment[0] | segment[1] | segment[2] | segment[3];
    }
}